<template>
	<view class="wrap">
		<Search @search-data="handleSearchData" v-show="false" />
		<view class="navProgramm">
			<u-subsection :list="tabList" :current="current" @change="sectionChange"></u-subsection>
		</view>
		<scroll-view class="scroll-list" scroll-y="true">
			<view v-if="showList1">
				<u-card class="task-list-item" :show-head="false" :border="true" padding="20" margin="20rpx"
					:head-border-bottom="false" v-for="(item,index) in NotList" :key="item.id">
					<view slot="body">
						<u-row gutter="16">
							<u-col span="12">
								<view class="apply-text"><text>{{item.maintain_order_number}}</text></view>
							</u-col>
							<u-col span="12">
								<view class="apply-text"><span>保养计划：</span>{{item.maintain_plan}}</view>
							</u-col>
							<u-col span="12">
								<view class="apply-text"><span>保养时间：</span>{{item.maintain_date}}</view>
							</u-col>
							<u-col span="12">
								<view class="apply-text"><span>保养人：</span></view>
							</u-col>
						</u-row>
					</view>
					<view @click="navToEdit(item.id)" class="apply-list-foot" slot="foot" style="text-align: right;">
						编辑工单
					</view>
				</u-card>
				<u-divider>已经到底了</u-divider>
			</view>
			<view v-if="showList2">
				<u-card class="task-list-item" :show-head="false" :border="true" padding="20" margin="20rpx"
					:head-border-bottom="false" v-for="(item,index) in FinishList" :key="item.id">
					<view slot="body">
						<u-row gutter="16">
							<u-col span="12">
								<view class="apply-text"><text>{{item.maintain_order_number}}</text></view>
							</u-col>
							<u-col span="12">
								<view class="apply-text"><span>保养计划：</span>{{item.maintain_plan}}</view>
							</u-col>
							<u-col span="12">
								<view class="apply-text"><span>保养时间：</span>{{item.maintain_date}}</view>
							</u-col>
							<u-col span="12">
								<view class="apply-text"><span>保养人：</span>{{item.nice_name}}</view>
							</u-col>
						</u-row>
					</view>
					<view @click="navTo(item.id)" class="apply-list-foot" slot="foot" style="text-align: right;">查看工单
					</view>
				</u-card>
				<u-divider>已经到底了</u-divider>
			</view>
		</scroll-view>
	</view>
</template>
<script>
	import Search from '@/components/headsearch/searchOrder.vue'

	export default {
		components: {
			Search
		},
		data() {
			return {
				//厂站
				searchData: '', // 用于保存接收到的数据
				//查询时间
				searchTime: '',
				tabList: [{
						name: '未完成'
					},
					{
						name: '已完成'
					}
				],
				current: 0,
				showList1: true,
				showList2: false,
				//未完成列表
				// NotList: [{
				// 	id: 1,
				// 	maintain_order_number: "BYXJ-903472942719959044",
				// 	maintain_plan: "测试",
				// 	maintain_date: "2023-09-25"
				// }],
				NotList: [],
				//完成列表
				FinishList: [{
					id: 1,
					maintain_order_number: "BYXJ-903472942719959044",
					maintain_plan: "测试",
					maintain_date: "2023-09-25",
					maintain_user: "阿英",
				}]
			}
		},
		methods: {
			navTo(id) {
				uni.navigateTo({
					url: "/pages/sys/order/upkeepView?id=" + id
				});
			},
			navToEdit(id) {
				uni.navigateTo({
					url: "/pages/sys/order/upkeepEdit?id=" + id
				});
			},

			//分段器回调
			sectionChange(index) {
				this.current = index;
				if (this.current == 0) {
					this.showList1 = true
					this.showList2 = false
				} else {
					this.showList1 = false
					this.showList2 = true
				}
				console.log(this.current)
			},
			handleSearchData(data, times) {
				this.searchData = data; // 接收到子组件传递过来的数据
				this.times = times; // 接收到子组件传递过来的数据
				this.searchFinished()
				this.searchNotdo()
			},
			//未完成列表
			searchNotdo() {
				this.$u.api.searchNotdo({
					"algorithmProcessId": "search_notdo",
					"param": {
						"data": {
							// factory_id: this.searchData,
							factory_id:  uni.getStorageSync('navId'),
							pageNumber: "1",
							pageSize: "20",
							maintain_date: this.times,
						}
					}
				}).then(res => {
					this.NotList = res.data.data.result
				}).catch(error => {
					this.$u.toast('查询异常');
					console.error(error);
				});
			},
			//完成列表
			searchFinished() {
				console.log(this.searchData, this.times, "完成列表")
				this.$u.api.searchNotdo({
					"algorithmProcessId": "search_finshed",
					"param": {
						"data": {
							// factory_id: this.searchData,
							 factory_id:  uni.getStorageSync('navId'),
							pageNumber: "1",
							pageSize: "20",
							maintain_date: this.times,
						}
					}
				}).then(res => {
					this.FinishList = res.data.data.result
				}).catch(error => {
					this.$u.toast('查询异常');
					console.error(error);
				});
			}
		},
	};
</script>
<style lang="scss" scoped>
	@import '../../../common/uni.css';
	@import 'style/upkeepOrder.css';
</style>